package j48;

import java.util.concurrent.*;

/**
 * @author chengshuai
 * @date 2021/4/17 23:19
 */
public class Test {
    /**
     * 固定线程池
     * @param nThreads
     * @return
     */
    public static ExecutorService newFixedThreadPool(int nThreads) {
        return new ThreadPoolExecutor(nThreads, nThreads,
                0L, TimeUnit.MICROSECONDS,
                new LinkedBlockingQueue<>());
    }
    /**
     * 单线程线程池
     * @return
     */
    public static ExecutorService newSingleThreadExecutor() {
        return new ThreadPoolExecutor(1, 1,
                0L, TimeUnit.MICROSECONDS,
                new LinkedBlockingQueue<>());
    }
    /**
     * 缓冲线程池
     * @return
     */
    public static ExecutorService newCachedThreadPool() {
        return new ThreadPoolExecutor(0, Integer.MAX_VALUE,
                60L, TimeUnit.SECONDS,
                new SynchronousQueue<Runnable>());
    }
}
